package com.qgzj.controller;

import com.qgzj.entity.Demo;
import com.qgzj.job.ScheduleTask;
import com.qgzj.response.CommonRes;
import com.qgzj.service.DemoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName TestController
 * @Description
 * @DATE 2019-11-03 17:39
 **/
@RestController
public class TestController {
    private static final Logger logger = LoggerFactory.getLogger(TestController.class);

    @Autowired
    DemoService demoService;
    @Autowired
    ScheduleTask jobTimer;

    @GetMapping()
    public Object health() {
        return "this is Ok";
    }


    @GetMapping("testEx")
    public Object testException() {
        if (1 != 0) {
            RuntimeException runtimeException = new RuntimeException();
            logger.error("此处报错", runtimeException);
            logger.info("打印结束");
            throw runtimeException;
        }
        return "this is a test for exception";
    }

    @GetMapping("insert")
    public CommonRes testInsert() {
        demoService.insert();
        return CommonRes.success("插入成功");
    }

    @GetMapping("select")
    public CommonRes testSelect() {
        List<Demo> select = demoService.select();
        return CommonRes.success(select);
    }

    @GetMapping("update")
    public CommonRes testUpdate() {
        demoService.update();
        return CommonRes.success("更新成功");
    }


    @GetMapping("ocrpic")
    public CommonRes testOcrPic() {
        jobTimer.timerRun();
        return CommonRes.success("更新成功");
    }

}
